/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mbos.facade;

import java.util.List;
import mbos.entities.Account;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

/**
 *
 * @author mier
 */
@Stateless
public class AccountFacade extends AbstractFacade<Account> {

    @PersistenceContext(unitName = "mbosPU")
    private EntityManager em;

    public AccountFacade() {
        super(Account.class);
    }

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    @Override
    protected EntityManager getEntityManager() {
        return em;
    }
    
    public List<Account> login(Account account){
        TypedQuery tq = em.createQuery("SELECT acct FROM Account acct WHERE acct.userName = :userName AND acct.password = :password", Account.class);
        tq.setParameter("userName", account.getUserName());
        tq.setParameter("password", account.getPassword());
        return  tq.getResultList();
    }
}
